import NP from 'number-precision'
// import _ from 'lodash'
import {
  getMarker,
  getMaxArrayLength,
  getTimeAndCountStr,
  getCurrentCountStr,
  getTheoreticalCountStr,
  getCurrentProbabilityStr,
  getTheoreticalProbabilityStr,
  getCurrentGroupStr
} from '@/utils/study.js'

/**
 * @desc /one/order-bar-line
 */
export const formatterForGroupOrderBarLine = function(params) {
  // 获取总长度
  const totalLength = this.allValues.length
  // 结果
  let result = ''

  params.forEach((item) => {
    if (item.seriesType === 'bar') {
      // 当前组号码
      const groups = item.data.groups

      // 理论次数
      const theoreticalAverage = NP.round(totalLength / groups.length, 2)

      // 理论概率
      const theoreticalProbability = NP.round(NP.divide(100, groups.length), 2)

      // 使用 number-precision 计算百分比并保留两位小数
      const percentage = NP.round(NP.times(NP.divide(item.value, totalLength), 100), 2)

      // 红色
      const redMarker = getMarker('rgba(255, 112, 112,1)')

      // 当前分组号码
      const groupNumber = item.data.groupNumber

      // 计算HTML容器的宽度
      const numberWidth = 25 // 每个号码占据的宽度（像素）
      const maxArrayLength = getMaxArrayLength(groupNumber, groupNumber) // 获取前期和当前组号数组的最大长度
      const width = `${maxArrayLength * numberWidth + 250}px` // 计算最终的宽度，确保内容能够正确显示和布局

      result += `<div class="flex flex-col" style="width: ${width};">
          ${getTimeAndCountStr(redMarker, item, totalLength)}
          ${getCurrentGroupStr(groupNumber)}
          ${getCurrentCountStr(item.value)}
          ${getTheoreticalCountStr(theoreticalAverage)}
          ${getCurrentProbabilityStr(percentage)}
          ${getTheoreticalProbabilityStr(theoreticalProbability)}
        </div>`
    }
  })
  return result
}
